package com.ulife.permission.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ulife.permission.dao.RoleDao;
import com.ulife.permission.dao.dataobject.RoleDO;

public class RoleDaoImpl extends SqlMapClientDaoSupport implements RoleDao {

	public RoleDO getRoleById(long roleId) throws SQLException {
		return (RoleDO)getSqlMapClient().queryForObject("Role.getRoleById",roleId);
	}

	public int addRole(RoleDO role) throws SQLException {
		return getSqlMapClient().update("Role.insertRole",role);
	}

	@SuppressWarnings("unchecked")
	public List<RoleDO> getAllRole() throws SQLException {
		return getSqlMapClient().queryForList("Role.selectAllRoles");
	}

	public int delUser(long roleId) throws SQLException {
		return getSqlMapClient().update("Role.delRole", roleId);
	}

	public int updateUser(RoleDO role) throws SQLException {
		return getSqlMapClient().update("Role.updateRoleInfo", role);
	}

	@SuppressWarnings("unchecked")
	public List<RoleDO> getAllAvailableRoles() throws SQLException {
		return getSqlMapClient().queryForList("Role.getAllAvailableRoles");
	}

}
